import MJCrequest from "./request/index";
import { DRUG_URL, TIME_OUT } from "./request/config.js";
import storage from "@/utils/storage.js";
import { Toast } from "vant";
//请求出口
const drugService = new MJCrequest({
  baseURL: DRUG_URL,
  timeout: TIME_OUT,
  interceptors: {
    requestInterceptor: (config) => {
      const token = storage.get("authorization");
      if (token) {
        config.headers.authorization = token;
      }
      return config;
    },
    requestInterceptorCatch: (config) => {
      console.log("请求失败");
      return config;
    },
    responseInterceptor: (res) => {
      if (res.data.msg) {
        Toast.fail(res.data.msg);
      }
      return res;
    },
    responseInterceptorCatch: (err) => {
      Toast.fail("网络出错了");
      return err.response;
    },
  },
});
export default drugService;
